<template>
    <view class="login-view">
        <image src="/static/logo.webp" mode="widthFix" />
        <button @tap="login">一键登录</button>
    </view>
</template>
<script setup lang="ts">
import request from '@/api/request';
import type { UserInfo } from '@/types';

const login = () => {
    uni.showLoading({ title: "登录中", mask: true })
    uni.login({
        provider: 'weixin',
        success: async (res) => {
            const { data } = await request<UserInfo>("/login", { code: res.code });
            uni.setStorageSync("userInfo", data);
            uni.hideLoading();
            uni.navigateBack();

        }
    });
};
</script>
<style>
.login-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: 100rpx;
    left: 0;
    right: 0;
    top: 0;
}

.login-view image {
    width: 150rpx;
    border-radius: 50%;
    margin-bottom: 90rpx;
}

.login-view button {
    padding: 20rpx 180rpx;
    background-color: #214bd5;
    color: #ffffff;
    font-size: 30rpx;
}
</style>